<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    let obj = {
        name: 'jack',
        age: 21,
        address: '苏州',
        location: '工业园区'
    }

    // 剩余运算符的使用
    let {name, ...other} = obj
    console.log(name, other)

    // 也可以作为参数
    function test(name, ...other) {
        console.log(name, other)
    }

    test(obj)


    // 展开运算符   用于合并，有的时候比Object.assign方便
    let obj2 = {
        name: 'marry',
        age: 23,
        address: '苏州吴中区'
    };
    let obj3 = {
        name: 'james',
        age: 25
    };
    let obj4 = {...obj2, ...obj3}; // 相同属性以后面为准
    console.log(obj4)

    // 使用场景
    function ajax(options) {
        const defaultOptions = {
            methods: 'get',
            async: true
        }
        options = {...defaultOptions, ...options}
        console.log(options)
    }

    ajax({url: '/api', methods: 'post'})

    // 复制对象-只能针对简单数据类型，复杂类型是引用
    let obj5 = {name: 'aaa', age: 18}
    let obj6 = {...obj5}
    console.log(obj6)
</script>
</body>
</html>
